﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IndyMosaic.Core.Notifications
{
    public abstract class SimpleNotifier : INotifier
    {
        protected SimpleNotifier(object trigger)
        {
            this.Trigger = trigger;
        }
        protected object Trigger { get; set; }
        private IEnumerable<Subscriber> subscribers;
        protected IEnumerable<Subscriber> Subscribers 
        {
            get
            {
                if (subscribers == null)
                {
                    subscribers = GetSubscribers();
                }
                return subscribers;
            }
        }

        protected string Message { get; set; }

        protected abstract IEnumerable<Subscriber> GetSubscribers();

        protected abstract void SendNotification();

        #region INotifier Members

        public void NotifySubscribers()
        {
            try
            {
                SendNotification();
            }
            catch
            {
            }
        }

        #endregion
    }
}
